package com.junjie.checkin.entity.Enum.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.junjie.checkin.entity.Enum.StringValuedEnum;

import java.io.IOException;

/**
 * @author 洪浚杰
 * @description
 * @date 2025/6/13 21:03
 */
public class LowercaseEnumSerializer extends JsonSerializer<Enum<?>> {

    @Override
    public void serialize(Enum<?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value instanceof StringValuedEnum) {
            gen.writeString(((StringValuedEnum) value).getValue());
        } else {
            gen.writeString(value.toString().toLowerCase());
        }
    }
}